<?php
namespace Entities\Cep;

use Doctrine\ORM\Query;
use Doctrine\ORM\EntityRepository;

class BairroRepository extends EntityRepository
{
	public function listar($params = array())
	{
		$qb		= $this->getEntityManager()->createQueryBuilder();
		$qb->select('b')
		->from('\Entities\Cep\Bairro', 'b');

		$where	= $qb->expr()->andX();
		$where->add($qb->expr()->eq(1,1));
		foreach ($params as $key => $value)
		{
			$where->add($qb->expr()->eq($key, "'".$value."'"));

		}
		$qb->where($where)
		->orderBy('b.bairro','ASC');

		//echo $qb->getQuery()->getSQL();die;
		return $qb->getQuery()->getResult(Query::HYDRATE_OBJECT);
	}

	public function listCombo($params = array())
	{
		$return	= array();
		foreach ($this->listar($params) as $value)
		{
			$return[$value->get('id_bairro')]	= $value->get('bairro');
		}
		return $return;
	}
}